//
//  LGCemeteryHomeViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/9.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGCemeteryHomeViewController.h"
#import "LGCemeteryHomeTableViewCell.h"
#import "LGGemeteryDetailViewController.h"
#import "LGGraveyardDetailViewController.h"
@interface LGCemeteryHomeViewController ()

@end

@implementation LGCemeteryHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"园林墓地";
    [self configSubView];
    // Do any additional setup after loading the view.
}

- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 20)];

    UIView * sectionHeader = [TMUtils headerViewWithTitle:@"陵园"];
    [header addSubview:sectionHeader];
    
    NSArray * array = @[@{@"title":@"八宝山",@"imageName":@"祭拜"},
                        @{@"title":@"永福",@"imageName":@"亲情值"},
                        @{@"title":@"凤凰",@"imageName":@"修缮值"},
                        @{@"title":@"皇恩寺",@"imageName":@"财富值"},
                        @{@"title":@"大朗",@"imageName":@"财富值"},
                        @{@"title":@"金沙",@"imageName":@"财富值"},
                        @{@"title":@"长松寿",@"imageName":@"财富值"},
                        @{@"title":@"莲花",@"imageName":@"财富值"},
                        ];
    CGFloat buttonWith = UIScreenWidth / 4;
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, sectionHeader.bottom, UIScreenWidth, buttonWith * 2)];
    imageView.userInteractionEnabled = YES;
    imageView.image = [UIImage imageNamed:@"首页bg"];
    [header addSubview:imageView];
    for (NSInteger i =0 ;i < array.count;i ++) {
        NSDictionary * dic = array[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        __weak typeof(self) weakSelf =  self;
        STMenuControl * menuControl = [[STMenuControl alloc] initWithFrame:CGRectMake(0, sectionHeader.bottom, buttonWith, buttonWith) imageName:imageName title:title titleColor:FirstTextColor];
        [menuControl setOnSelctedControl:^(STMenuControl *control) {
            [weakSelf onSelctedMenuControlWithTag:control];
        }];
        menuControl.tag = 10000 + i;
        [header addSubview:menuControl];
        
        menuControl.left = (i%4) * buttonWith;
        menuControl.top = sectionHeader.bottom +(i/4) * buttonWith;
    }
    
    UIView * sectionHeader1 = [TMUtils headerViewWithTitle:@"推荐陵园"];
    sectionHeader1.top =  sectionHeader.bottom + 2 * buttonWith;
    [header addSubview:sectionHeader1];
    
    NSArray * array1 = @[@{@"title":@"八宝山",@"imageName":@"祭拜"},
                        @{@"title":@"永福",@"imageName":@"亲情值"},
                        @{@"title":@"凤凰",@"imageName":@"修缮值"},
                        @{@"title":@"皇恩寺",@"imageName":@"财富值"}
                        ];
    
    UIImageView * imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, sectionHeader1.bottom, UIScreenWidth, buttonWith * 1)];
    imageView1.userInteractionEnabled = YES;
    imageView1.image = [UIImage imageNamed:@"首页bg"];
    [header addSubview:imageView1];
    
    
    for (NSInteger i =0 ;i < array1.count;i ++) {
        NSDictionary * dic = array1[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        __weak typeof(self) weakSelf =  self;
        STMenuControl * menuControl = [[STMenuControl alloc] initWithFrame:CGRectMake(0, sectionHeader1.bottom, buttonWith, buttonWith) imageName:imageName title:title titleColor:FirstTextColor];
        [menuControl setOnSelctedControl:^(STMenuControl *control) {
            [weakSelf onSelctedMenuControlWithTag:control];
        }];
        menuControl.tag = 10008 + i;
        [header addSubview:menuControl];
        
        menuControl.left = (i%4) * buttonWith;
        menuControl.top = sectionHeader1.bottom +(i/4) * buttonWith;
    }
    
    
     UIView * sectionHeader3 = [TMUtils headerViewWithTitle:@"推荐墓地"];
    sectionHeader3.top = sectionHeader1.bottom + buttonWith;
    [header addSubview:sectionHeader3];
    
    
    header.height = sectionHeader3.bottom ;
    self.tableView.tableHeaderView = header;
    
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10   ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGCemeteryHomeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGCemeteryHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGCemeteryHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    __weak typeof(self) weakSelf =  self;
    [cell.lookButton setClicAction:^(UIButton *sender) {
        STWebViewController * webVC = [[STWebViewController alloc] initWithUrl:@"http://jiangqingqian.mzgtuan.com/vrpano/vrpano20/"];
        [weakSelf.navigationController pushViewController:webVC animated:YES];
    }];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.navigationController pushViewController:[LGGraveyardDetailViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)onSelctedMenuControlWithTag:(STMenuControl*)sender{
    [self.navigationController pushViewController:[LGGemeteryDetailViewController new] animated:YES];
}
@end
